package com.ruoyi.jihuo.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author：HMH
 * @DATE：2025-07-26
 * @Description：
 */
public class MultipartFileUtils {


    /**
     * txt文件读取
     * @param file 导入文件
     * @return 集合
     */
    public static List<String> readTxtToList(MultipartFile file) {
        List<String> result = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String trimmed = line.trim();
                if (!trimmed.isEmpty()) {
                    result.add(trimmed);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException("读取txt失败", e);
        }
        return result;
    }
}
